package com.example.lianxi1.adapter;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.lianxi1.AlbumsBean;
import com.example.lianxi1.Bean;
import com.example.lianxi1.R;

import java.io.Serializable;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListFragment extends Fragment {


    private RecyclerView mRecl;
    private ListAdapter listAdapter;

    public ListFragment() {
        // Required empty public constructor
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Bundle arguments = getArguments();
        List<AlbumsBean> list = (List<AlbumsBean>) arguments.getSerializable("list");
        listAdapter.addList(list);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_list, container, false);
        initView(inflate);
        return inflate;
    }

    private void initView(@NonNull final View itemView) {
        mRecl = (RecyclerView) itemView.findViewById(R.id.recl);
        mRecl.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecl.addItemDecoration(new DividerItemDecoration(getContext(),DividerItemDecoration.VERTICAL));

        listAdapter = new ListAdapter(getContext());
        mRecl.setAdapter(listAdapter);
    }

}
